
ssc install lgraph
ssc install outreg2

use "DMMW_replication_data.dta", replace

*log using "DMMW_log_file.log", replace

*****************************************************
********** Figures and Tables Main Text *************
*****************************************************

*** Figure 2 ***

lgraph coop block if (treat==402 | treat==1402 | treat==2412), ylabel(0(0.2)1) xlabel(1(1)10) xlabel(1 "1-5", add) xlabel(2 "6-10", add) xlabel(3 "11-15", add) xlabel(4 "16-20", add) xlabel(5 "21-25", add) xlabel(6 "26-30", add) xlabel(7 "31-35", add) xlabel(8 "36-40", add) xlabel(9 "41-45", add) xlabel(10 "46-50", add) legend(rows(1)) xtitle(''period'') ytitle(''Contribution Rate'') errortype(semean) bw legend(on order(1 "No" 2 "Standard" 3 "Collective")) by(treat) loptions(402 mcolor(gray); 1402 lcolor(black) mfcolor(white) msymbol(S); 2412 lcolor(black) mcolor(black) lpattern(solid)) eoptions(402 lcolor(gray))

*** Table 2 ***

gen periodT7=period*T7
gen periodT10=period*T10

reg coop T7 T10 if treat==402 | treat==1402 | treat==2412, cluster(mgroup)
test T7=T10
outreg2 using Table2.tex, replace ctitle(All Periods)
reg coop T7 T10 period periodT7 periodT10 if (treat==402 | treat==1402 | treat==2412), cluster(mgroup)
test T7=T10
outreg2 using Table2.tex, append ctitle(Time Trend)
reg coop T7 T10 if (treat==402 | treat==1402 | treat==2412) & period<26, cluster(mgroup)
test T7=T10
outreg2 using Table2.tex, append ctitle(1st Half)
reg coop T7 T10 if (treat==402 | treat==1402 | treat==2412) & period>25, cluster(mgroup)
test T7=T10
outreg2 using Table2.tex, append ctitle(2nd Half)
reg coop T7 T10 if (treat==402 | treat==1402 | treat==2412) & period>40, cluster(mgroup)
test T7=T10
outreg2 using Table2.tex, append ctitle(Last 10 periods)

*** Figure 3 ***

lgraph netprofit block if treat==402 | treat==1402 | treat==2412, xlabel(1(1)10) xlabel(1 "1-5", add) xlabel(2 "6-10", add) xlabel(3 "11-15", add) xlabel(4 "16-20", add) xlabel(5 "21-25", add) xlabel(6 "26-30", add) xlabel(7 "31-35", add) xlabel(8 "36-40", add) xlabel(9 "41-45", add) xlabel(10 "46-50", add) legend(rows(1)) xtitle(''period'') ytitle(''Net Profits'') errortype(semean) bw legend(on order(1 "No" 2 "Standard" 3 "Collective")) by(treat) loptions(402 mcolor(gray); 1402 lcolor(black) mfcolor(white) msymbol(S); 2412 lcolor(black) mcolor(black) lpattern(solid)) eoptions(402 lcolor(gray))

*** Table 3 ***

reg netprofit T7 T10 if treat==402 | treat==1402 | treat==2412, cluster(mgroup)
test T7=T10
outreg2 using Table3.tex, replace ctitle(All Periods)
reg netprofit T7 T10 period periodT7 periodT10 if (treat==402 | treat==1402 | treat==2412), cluster(mgroup)
test T7=T10
outreg2 using Table3.tex, append ctitle(Time Trend)
reg netprofit T7 T10 if (treat==402 | treat==1402 | treat==2412) & period<26, cluster(mgroup)
test T7=T10
outreg2 using Table3.tex, append ctitle(1st Half)
reg netprofit T7 T10 if (treat==402 | treat==1402 | treat==2412) & period>25, cluster(mgroup)
test T7=T10
outreg2 using Table3.tex, append ctitle(2nd Half)
reg netprofit T7 T10 if (treat==402 | treat==1402 | treat==2412) & period>40, cluster(mgroup)
test T7=T10
outreg2 using Table3.tex, append ctitle(Last 10 periods)

*** Figure 4 ***
lgraph coop block if treat==2412 | treat==402,  ylabel(0(0.2)1) xlabel(1(1)10) xlabel(1 "1-5", add) xlabel(2 "6-10", add) xlabel(3 "11-15", add) xlabel(4 "16-20", add) xlabel(5 "21-25", add) xlabel(6 "26-30", add) xlabel(7 "31-35", add) xlabel(8 "36-40", add) xlabel(9 "41-45", add) xlabel(10 "46-50", add) legend(rows(1)) xtitle(''period'') ytitle(''Contribution Rate'') errortype(semean) bw legend(on order(1 "Not committed" 2 "committed" 3 "N treatment")) by(rdecision) loptions(1 lcolor(gray) mcolor(gray) lpattern(solid) msymbol(o); 2 lcolor(black) mcolor(black) msymbol(o) lpattern(solid); 99 lcolor(gs12) mcolor(gs12) lpattern(dash) msymbol(o)) eoptions(1 lcolor(gray); 2 lcolor(black) lpattern(solid); 99 lcolor(gs12) lpattern(solid))

**** Table 4 ****

* Table manually assembled from the following.

* contribution rates
sort shareforcpun rdecision
by shareforcpun rdecision: summarize coop if treat==2412

sort rdecision
by rdecision: summarize coop if treat==2412

* profits
sort shareforcpun rdecision
by shareforcpun rdecision: summarize netprofit if treat==2412

sort rdecision
by rdecision: summarize netprofit if treat==2412

**** Figure 5 ****

lgraph netprofit block if treat==2412 | treat==402, xlabel(1(1)10) xlabel(1 "1-5", add) xlabel(2 "6-10", add) xlabel(3 "11-15", add) xlabel(4 "16-20", add) xlabel(5 "21-25", add) xlabel(6 "26-30", add) xlabel(7 "31-35", add) xlabel(8 "36-40", add) xlabel(9 "41-45", add) xlabel(10 "46-50", add) legend(rows(1)) xtitle(''period'') ytitle(''Net profits'') errortype(semean) bw legend(on order(1 "Not committed" 2 "committed" 3 "N treatment"))  by(rdecision) loptions(1 lcolor(gray) mcolor(gray) lpattern(solid) msymbol(o); 2 lcolor(black) mcolor(black) msymbol(o) lpattern(solid); 99 lcolor(gs12) mcolor(gs12) lpattern(dash) msymbol(o)) eoptions(1 lcolor(gray); 2 lcolor(black) lpattern(solid); 99 lcolor(gs12) lpattern(solid))

**** Table 5 ****

reg coop commit coll collXcommit if treat==1402 | treat==1412 | treat==2402| treat==2412, cluster(mgroup)
test coll+collXcommit=0
test commit+collXcommit=0
outreg2 using Table5.tex, replace ctitle(All Periods)
reg coop commit coll collXcommit period periodXcommit periodXcoll periodXcommitXcoll if (treat==1402 | treat==1412 | treat==2402| treat==2412), cluster(mgroup)
test coll+collXcommit=0
test commit+collXcommit=0
outreg2 using Table5.tex, append ctitle(Time Trend)
reg coop commit coll collXcommit if (treat==1402 | treat==1412 | treat==2402| treat==2412) & period<26, cluster(mgroup)
test coll+collXcommit=0
test commit+collXcommit=0
outreg2 using Table5.tex, append ctitle(1st Half)
reg coop commit coll collXcommit if (treat==1402 | treat==1412 | treat==2402| treat==2412) & period>25, cluster(mgroup)
test coll+collXcommit=0
test commit+collXcommit=0
outreg2 using Table5.tex, append ctitle(2nd Half)
reg coop commit coll collXcommit if (treat==1402 | treat==1412 | treat==2402| treat==2412) & period>40, cluster(mgroup)
test coll+collXcommit=0
test commit+collXcommit=0
outreg2 using Table5.tex, append ctitle(Last 10 periods)


**** Table 6 ****

reg netprofit commit coll collXcommit if treat==1402 | treat==1412 | treat==2402| treat==2412, cluster(mgroup)
test coll+collXcommit=0
test commit+collXcommit=0
outreg2 using Table6.tex, replace ctitle(All Periods)
reg netprofit commit coll collXcommit period periodXcommit periodXcoll periodXcommitXcoll if (treat==1402 | treat==1412 | treat==2402| treat==2412), cluster(mgroup)
test coll+collXcommit=0
test commit+collXcommit=0
outreg2 using Table6.tex, append ctitle(Time Trend)
reg netprofit commit coll collXcommit if (treat==1402 | treat==1412 | treat==2402| treat==2412) & period<26, cluster(mgroup)
test coll+collXcommit=0
test commit+collXcommit=0
outreg2 using Table6.tex, append ctitle(1st Half)
reg netprofit commit coll collXcommit if (treat==1402 | treat==1412 | treat==2402| treat==2412) & period>25, cluster(mgroup)
test coll+collXcommit=0
test commit+collXcommit=0
outreg2 using Table6.tex, append ctitle(2nd Half)
reg netprofit commit coll collXcommit if (treat==1402 | treat==1412 | treat==2402| treat==2412) & period>40, cluster(mgroup)
test coll+collXcommit=0
test commit+collXcommit=0
outreg2 using Table6.tex, append ctitle(Last 10 periods)

**** Figure 6 ****

lgraph lost block if treat==1402 | treat==1412 | treat==2402 | treat==2412,xlabel(1(1)10) xlabel(1 "1-5", add) xlabel(2 "6-10", add) xlabel(3 "11-15", add) xlabel(4 "16-20", add) xlabel(5 "21-25", add) xlabel(6 "26-30", add) xlabel(7 "31-35", add) xlabel(8 "36-40", add) xlabel(9 "41-45", add) xlabel(10 "46-50", add) legend(rows(1)) xtitle(''period'') ytitle(''Amount lost on punishment'') errortype(semean) bw legend(on order(1 "S" 2 "S-Comm" 3 "C" 4 "C-Comm")) by(treat) loptions(1402 mlcolor(gray) mfcolor(white) msymbol(S) lpatter(dash); 1412 lcolor(gray) mcolor(gray) msymbol(S) lpatter(dash); 2402 lcolor(black) mlcolor(black) mfcolor(white) msymbol(D) lpattern(solid); 2412 lcolor(black) mcolor(black) msymbol(D) lpattern(solid)) eoptions(1402 lcolor(gray) lpattern(solid); 1412 lcolor(gray) lpattern(solid); 2402 lcolor(black) lpattern(solid); 2412 lcolor(black) lpattern(solid))


*************************************************
***************** Appendix **********************
*************************************************

**** Figure 7 *****

lgraph coop block if treat==402 | treat==1402 | treat==14026, ylabel(0(0.2)1) xlabel(1(1)10) xlabel(1 "1-5", add) xlabel(2 "6-10", add) xlabel(3 "11-15", add) xlabel(4 "16-20", add) xlabel(5 "21-25", add) xlabel(6 "26-30", add) xlabel(7 "31-35", add) xlabel(8 "36-40", add) xlabel(9 "41-45", add) xlabel(10 "46-50", add) legend(rows(1)) xtitle(''period'') ytitle(''Contribution Rate'') errortype(semean) bw legend(on order(1 "No" 2 "S" 3 "S-Strong")) by(treat) loptions(402 mcolor(gray) msymbol(o) lcolor(gray) lpatter(solid); 1402 lcolor(black) mlcolor(black) mfcolor(white) msymbol(S) lpatter(dash); 14026 lcolor(black) mlcolor(black) mfcolor(white) msymbol(Oh) lpattern(dash)) eoptions(402 lcolor(gray) lpattern(solid); 1402 lcolor(black) lpattern(solid); 14026 lcolor(black) lpattern(solid))

lgraph netprofit block if treat==402 | treat==1402 | treat==14026, ylabel(0(10)40) xlabel(1(1)10) xlabel(1 "1-5", add) xlabel(2 "6-10", add) xlabel(3 "11-15", add) xlabel(4 "16-20", add) xlabel(5 "21-25", add) xlabel(6 "26-30", add) xlabel(7 "31-35", add) xlabel(8 "36-40", add) xlabel(9 "41-45", add) xlabel(10 "46-50", add) legend(rows(1)) xtitle(''period'') ytitle(''Net profits'') errortype(semean) bw legend(on order(1 "No" 2 "S" 3 "S-Strong")) by(treat) loptions(402 mcolor(gray) msymbol(o) lcolor(gray) lpatter(solid); 1402 lcolor(black) mlcolor(black) mfcolor(white) msymbol(S) lpatter(dash); 14026 lcolor(black) mlcolor(black) mfcolor(white) msymbol(Oh) lpattern(dash)) eoptions(402 lcolor(gray) lpattern(solid); 1402 lcolor(black) lpattern(solid); 14026 lcolor(black) lpattern(solid))
	
**** Figure 8 ****

lgraph coop block if treat==1 | treat==1402, ylabel(0(0.2)1) xlabel(1(1)10) xlabel(1 "1-5", add) xlabel(2 "6-10", add) xlabel(3 "11-15", add) xlabel(4 "16-20", add) xlabel(5 "21-25", add) xlabel(6 "26-30", add) xlabel(7 "31-35", add) xlabel(8 "36-40", add) xlabel(9 "41-45", add) xlabel(10 "46-50", add) legend(rows(1)) xtitle(''period'') ytitle(''Contribution Rate'') errortype(semean) bw legend(on order(1 "S-0.1" 2 "S")) by(treat) loptions(1 mcolor(black) msymbol(X) lcolor(black) lpatter(dash); 1402 lcolor(black) mlcolor(black) mfcolor(white) msymbol(S) lpatter(dash)) eoptions(1 lcolor(black) lpattern(solid); 1402 lcolor(black) lpattern(solid))
	

lgraph coop block if treat==24120 | treat==2402 | treat==2412, ylabel(0(0.2)1) xlabel(1(1)10) xlabel(1 "1-5", add) xlabel(2 "6-10", add) xlabel(3 "11-15", add) xlabel(4 "16-20", add) xlabel(5 "21-25", add) xlabel(6 "26-30", add) xlabel(7 "31-35", add) xlabel(8 "36-40", add) xlabel(9 "41-45", add) xlabel(10 "46-50", add) legend(rows(1)) xtitle(''period'') ytitle(''Contribution Rate'') errortype(semean) bw legend(on order(1 "C" 2 "C-COMM" 3 "C-COMM-levels")) by(treat) loptions(24120 mcolor(black) msymbol(X) lcolor(black) lpatter(solid); 2402 lcolor(black) mlcolor(black) mfcolor(white) msymbol(d) lpatter(solid); 2412 lcolor(black) mcolor(black) msymbol(d) lpattern(solid)) eoptions(24120 lcolor(black) lpattern(solid); 2402 lcolor(black) lpattern(solid); 2412 lcolor(black) lpattern(solid))

**** Table 7 ****

keep if treat==402 | treat==1402 | treat==1412 | treat==2402 | treat==2412

foreach var of varlist gender subjectage clas1 clas2 clas3 clas4 risk trust rec recn {
	reg `var' T7 T8 T9 T10 if period==1, cluster(mgroup)
	outreg2 using Table7.tex, append ctitle(`var')
	}

log close

clear
